﻿using System;
using System.Windows.Forms;
using System.IO;
using System.Collections.Generic;
using _CUSTOM_CONTROLS._ChatListBox;
using System.Drawing;

namespace LazyFun
{
    public partial class LazyFunPanel : Form
    {
        const string _custom_inf_path = "./CustomInfo.xls";

        public static Dictionary<string, List<AppInfomation>> _dic_group_infos;
        public static Dictionary<int, CustomInfo> _dic_custom_inf;
        public static List<AppInfomation> info_list;
        JobAdd jobadd;

        public LazyFunPanel()
        {
            InitializeComponent();
            InitData();
            //InitDraw();

        }

        private void InitDraw()
        {
            //foreach (string groupName in _dic_group_infos.Keys)
            //{
            //    ChatListItem item = new ChatListItem(groupName);
            //    foreach (AppInfomation appInfo in _dic_group_infos[groupName])
            //    {
            //        ChatListSubItem subItem = new ChatListSubItem(appInfo._custom_app_name + appInfo._custom_app_name, appInfo._version_info, "");
            //        if (!File.Exists(appInfo._icon_path))
            //            subItem.HeadImage = Image.FromFile(string.Format("{0}/{1}.png", PathParser._image_path, "default"));
            //        else
            //            subItem.HeadImage = Image.FromFile(appInfo._icon_path);
            //        item.SubItems.AddAccordingToStatus(subItem);
            //    }
            //    item.SubItems.Sort();
            //    my_chatlist.Items.Add(item);
            //}
        }

        private void InitData()
        {
            if (File.Exists(_custom_inf_path))
            {
                _dic_group_infos = new Dictionary<string, List<AppInfomation>>();
            }

            //加载app路径
            if (File.Exists(PathParser._appinfo_path))
            {
                byte[] bytes = File.ReadAllBytes(PathParser._appinfo_path);
                AppInfos infos = SerializeHelper.DeserializeWithBinary<AppInfos>(bytes);
                info_list = infos.info_list;
                if (info_list.Count > 0)
                {
                    foreach (var item in info_list)
                    {
                        if (_dic_group_infos.ContainsKey(item._group_name))
                        {
                            _dic_group_infos[item._group_name].Add(item);
                        }
                        else
                        {
                            List<AppInfomation> temp = new List<AppInfomation>();
                            temp.Add(item);
                            _dic_group_infos.Add(item._group_name, temp);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("还没有初始化!");
            }
        }

        #region 菜单

        private void 刷新信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PathParser.Instance.StartPraser();
            MessageBox.Show("信息刷新成功!");
            PathParser.DestroyInstance();
        }

        private void 打开对应文件夹ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void app配置文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 其它信息配置文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 添加快捷任务ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            jobadd = new JobAdd();
            jobadd.Show();
        }

        private void DoubleClickSubItem(object sender, _CUSTOM_CONTROLS._ChatListBox.ChatListEventArgs e)
        {

        }

        #endregion

    }
}
